home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2 (Special) / PCPro-2b.iso / Demos / Macromedia / CourseBuilder / CourseBuilderInstaller.exe / Disk1 / data1.cab / Dreamweaver-unInstalled / Configuration / Commands / Cut Interaction.js < prev    next >
Encoding:
JavaScript  |  1999-12-06  |  1.9 KB  |  81 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS VARS *****************
  4.  
  5. //******************* API **********************
  6.  
  7. //***************** LOCAL FUNCTIONS  ******************
  8.  
  9. function initialize() {
  10.   MM.event.handled = cutObject();
  11.   window.close();
  12. }
  13.  
  14.  
  15. function cutObject() {
  16.   var docDOM, attainDOM, theSel, fullSrc, retVal = false;
  17.     
  18.   // get the source
  19.   docDOM = dw.getDocumentDOM();
  20.   theSel = docDOM.getSelection();  
  21.   fullSrc = getSelectedSrc(theSel);
  22.  
  23.   if (fullSrc.search(/<interaction/gi) == -1 &&
  24.       fullSrc.search(/<\/interaction>/gi) == -1) {
  25.     return retVal;
  26.   }
  27.   
  28.   // make selection valid
  29.   theSel = makeValidSelection(theSel);
  30.   fullSrc = getSelectedSrc(theSel);
  31.  
  32.   if (fullSrc.search(/<interaction/gi) == -1 &&
  33.       fullSrc.search(/<\/interaction>/gi) == -1) {
  34.     return retVal;
  35.   }
  36.   
  37.   if (!regCheck()) {
  38.     return retVal;
  39.   }
  40.   
  41.   setBusyCursor();
  42.  
  43.   setNewline(); //init NEWLINE global
  44.  
  45.   // create the dom objects
  46.   attainDOM = new AttainDOM();
  47.   
  48.   // remove the source
  49.   dw.clipCut();
  50.   attainDOM.removeSrc(fullSrc);
  51.   retVal = true;
  52.  
  53.   clearBusyCursor();
  54.  
  55.   garbageCollect(true);
  56.   
  57.   return retVal;
  58. }
  59.  
  60.  
  61. function makeValidSelection(theSel) {
  62.   var docDOM, objList, attainSel, newSel = '';
  63.   docDOM = dw.getDocumentDOM();
  64.   objList = getAttainObjs();
  65.   for (var i=0; !newSel && i < objList.length; i++) {
  66.     attainSel = docDOM.nodeToOffsets(objList[i]);
  67.     if (theSel[0] < attainSel[0] && 
  68.         theSel[1] > attainSel[0] && theSel[1] < attainSel[1]) 
  69.       newSel = new Array(theSel[0], attainSel[0]);
  70.     if (theSel[1] > attainSel[1] && 
  71.         theSel[0] > attainSel[0] && theSel[0] < attainSel[1]) 
  72.       newSel = new Array(attainSel[1], theSel[1]);
  73.   } 
  74.   if (newSel) {
  75.     docDOM.setSelection(newSel[0], newSel[1]);
  76.     return newSel;
  77.   } else {
  78.     return theSel;
  79.   }
  80. }
  81.